package com.micro.modual.service.impl;

import com.micro.common.MicroResponseCode;
import com.micro.core.exception.BizException;
import com.micro.core.frame.service.impl.AbstractBasicsServiceImpl;
import com.micro.core.resp.RespJson;
import com.micro.modual.entity.Coupon;
import com.micro.modual.extension.CouponExtension;
import com.micro.modual.mapper.CouponMapper;
import com.micro.modual.model.bo.coupon.CouponBO;
import com.micro.modual.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
*  <h1>优惠券表  实现</h1>
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:11:10
 */
@Service("couponService")
public class CouponServiceImpl extends AbstractBasicsServiceImpl<Coupon,Long> implements CouponService {

    @Autowired
    private CouponMapper couponMapper;

    /**
     * <h2>新增优惠券表详情</h2>
     * @param couponBO {@link CouponBO} 优惠券表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson addCoupon(CouponBO couponBO) {
        Coupon coupon = CouponExtension.converAddCoupon(couponBO);
        couponMapper.insertSelective(coupon);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(), MicroResponseCode.SUCCESS.getResponseMessage());
    }

    /**
     * <h2>修改优惠券表详情</h2>
     * @param couponBO  {@link CouponBO} 优惠券表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson editCoupon(CouponBO couponBO) {
        Coupon coupon = CouponExtension.converEditCoupon(couponBO);
        couponMapper.updateByPrimaryKeySelective(coupon);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());

    }

    /**
     * <h2>根据主键编号删除优惠券表信息</h2>
     * @param id  优惠券表 主键编号
     * @return  {@link RespJson} 返回结果基础类
     */

    @Override
    public RespJson deleteCoupon(Long id) {
        couponMapper.deleteByPrimaryKey(id);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());
    }

}
